package org.xbzheng.restful_study.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xbzheng.restful_study.model.User;
import org.xbzheng.restful_study.service.UserService;
import org.xbzheng.restful_study.util.ResponseEntity;

/**
 * @Created by xiaobing.zheng on 2016-12-09.
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService service;

    @RequestMapping("/")
    @ResponseBody
    public String getUsers(){
        return service.getAllUsersJson();
    }

    @RequestMapping("/save")
    @ResponseBody
    public ResponseEntity save(@RequestBody final User user){
        return service.save(user);
    }

    @RequestMapping("/remove")
    @ResponseBody
    /**
     * @RequestParam 用来处理form表单的数据
     * @RequestBody 用来处理非form表单的json数据
     */
    public ResponseEntity remove(@RequestBody final String ids){
        return service.remove(ids);
    }
}

